﻿/*******************************************************************************************************************************************
Modification History:
********************************************************************************************************************************************
Date		Author		    Description
********************************************************************************************************************************************
05/07/2011	Brian Kuhn	    Created SubscriptionChangeRequest class
*******************************************************************************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Runtime.Serialization;

namespace Concise.ServiceModel.Channels
{
    /// <summary>
    /// Represents a request to subscribe to or unsubscribe from one or more message types.
    /// </summary>
    [Export(typeof(IMessage)), DataContract()]
    public class SubscriptionChangeRequest : IMessage
    {
        //=======================================================================================================
        //  Constructors
        //=======================================================================================================
        #region SubscriptionChangeRequest()
        /// <summary>
        /// Initializes a new instance of the <see cref="SubscriptionChangeRequest"/> class.
        /// </summary>
        public SubscriptionChangeRequest()
        {

        }
        #endregion

        #region SubscriptionChangeRequest(IEnumerable<Type> subscribeTo, IEnumerable<Type> unsubscribeFrom)
        /// <summary>
        /// Initializes a new instance of the <see cref="SubscriptionChangeRequest"/> class 
        /// using the message types that are being changed.
        /// </summary>
        /// <param name="subscribeTo">The messages types being subscribed to. Can be <see langword="null"/>.</param>
        /// <param name="unsubscribeFrom">The messages types being unsubscribed from. Can be <see langword="null"/>.</param>
        public SubscriptionChangeRequest(IEnumerable<Type> subscribeTo, IEnumerable<Type> unsubscribeFrom) : this()
        {
            if (subscribeTo != null)
            {
                foreach (var type in subscribeTo)
                {
                    if(type != null)
                    {
                        this.SubscribeTo.Add(type.AssemblyQualifiedName);
                    }
                }
            }

            if (unsubscribeFrom != null)
            {
                foreach (var type in unsubscribeFrom)
                {
                    if (type != null)
                    {
                        this.UnsubscribeFrom.Add(type.AssemblyQualifiedName);
                    }
                }
            }
        }
        #endregion

        //=======================================================================================================
        //  Public Properties
        //=======================================================================================================
        #region SubscribeTo
        /// <summary>
        /// Gets the assembly-qualified names of the messages types being subscribed to.
        /// </summary>
        /// <value>
        /// A <see cref="List{String}"/> collection that contains the assembly-qualified names of the messages types being subscribed to. 
        /// The default value is an <i>empty</i> collection.
        /// </value>
        [DataMember()]
        public List<string> SubscribeTo
        {
            get
            {
                if (_changeRequestSubscribeTo == null)
                {
                    _changeRequestSubscribeTo = new List<string>();
                }
                return _changeRequestSubscribeTo;
            }
        }
        private List<string> _changeRequestSubscribeTo;
        #endregion

        #region UnsubscribeFrom
        /// <summary>
        /// Gets the assembly-qualified names of the messages types being unsubscribed from.
        /// </summary>
        /// <value>
        /// A <see cref="List{String}"/> collection that contains the assembly-qualified names of the messages types being unsubscribed from. 
        /// The default value is an <i>empty</i> collection.
        /// </value>
        [DataMember()]
        public List<string> UnsubscribeFrom
        {
            get
            {
                if (_changeRequestUnsubscribeFrom == null)
                {
                    _changeRequestUnsubscribeFrom = new List<string>();
                }
                return _changeRequestUnsubscribeFrom;
            }
        }
        private List<string> _changeRequestUnsubscribeFrom;
        #endregion
    }
}
